﻿package com.tudou.home.model.ad
{
    import com.tudou.ad.events.*;
    import com.tudou.ad.view.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.model.ad.base.*;
    import com.tudou.track.*;

    public class AdFrontProxy extends AdVideoProxyBase
    {
        public static const NAME:String = "AdFrontProxy";

        public function AdFrontProxy()
        {
            super(NAME);
            return;
        }// end function

        override protected function viewEventHlr(event:AdItemViewEvent) : void
        {
            switch(event.type)
            {
                case AdItemViewEvent.SHOW_START:
                {
                    sendNotification(AdFrontCommandSet.SHOW_START);
                    break;
                }
                case AdItemViewEvent.SHOW_NEAR_END:
                {
                    sendNotification(AdFrontCommandSet.SHOW_NEAR_END);
                    break;
                }
                case AdItemViewEvent.SHOW_END:
                {
                    if (view.isSkip)
                    {
                        sendNotification(AdFrontCommandSet.ERROR_END);
                    }
                    else
                    {
                        reduceRemainDt();
                        sendNotification(AdFrontCommandSet.SHOW_END);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        override protected function getRemainDt() : int
        {
            var _loc_1:* = facade.retrieveProxy(AdFrontMultiProxy.NAME) as AdFrontMultiProxy;
            return _loc_1.frontRemainDt;
        }// end function

        override protected function frontStuffComplete() : void
        {
            sendNotification(AdFrontCommandSet.PREPARE_TO_SHOW);
            return;
        }// end function

        public function timeoutStartPlay() : void
        {
            frontStuffTimeout();
            sendTrack(NodeLog.AD_TIMEOUT_START_PLAY_SKIP);
            if (!adItemInfo.isVideo)
            {
                adSkip();
            }
            return;
        }// end function

        override protected function adErrorEnd() : void
        {
            sendNotification(AdFrontCommandSet.ERROR_END);
            return;
        }// end function

        override public function startView() : void
        {
            if (!startViewCommon())
            {
                return;
            }
            view = new AdFrontView();
            startViewFronts();
            if (!view)
            {
                return;
            }
            loadBg();
            return;
        }// end function

        private function reduceRemainDt() : void
        {
            var _loc_1:AdFrontMultiProxy = null;
            if (view)
            {
                _loc_1 = facade.retrieveProxy(AdFrontMultiProxy.NAME) as AdFrontMultiProxy;
                if (view.etime > 0)
                {
                    _loc_1.reduceRemainDt(view.etime);
                }
            }
            return;
        }// end function

        override protected function delayTimerComplete() : void
        {
            loadV2();
            loadFront();
            return;
        }// end function

        override protected function frontStuffError() : void
        {
            adSkip();
            adErrorEnd();
            return;
        }// end function

    }
}
